package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.ConfineSumType;

/**
 * 交易限制设置
 * @author Moyq5
 * @date 2018年10月26日
 */
@Entity
@Table(name = "tra_confine")
@DynamicUpdate
public class TraConfine implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 交易限制设置ID（主键）
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "confine_id")
	private Long confineId;
	/**
	 * 单笔最小金额（元）
	 */
	@Column(name = "amount_min", precision = 10, scale = 2, columnDefinition = "decimal(10,2) not null default '0.01'")
	private BigDecimal amountMin;
	/**
	 * 单笔最大金额（元）
	 */
	@Column(name = "amount_max", precision = 10, scale = 2, columnDefinition = "decimal(10,2) not null default '99999.99'")
	private BigDecimal amountMax;
	/**
	 * 日最大交易金额（元）
	 */
	@Column(name = "amount_day", precision = 10, scale = 2, columnDefinition = "decimal(15,2) not null default '99999999.99'")
	private BigDecimal amountDay;
	/**
	 * 月最大交易金额（元）
	 */
	@Column(name = "amount_mon", precision = 10, scale = 2, columnDefinition = "decimal(15,2) not null default '9999999999.99'")
	private BigDecimal amountMon;
	/**
	 * 日、月限额统计方式
	 */
	@Enumerated(EnumType.ORDINAL)
    @Column(name = "sum_type", precision = 2, nullable = false, columnDefinition = "tinyint not null default '0'")
	private ConfineSumType sumType;
	/**
	 * 允许交易金额（s），多个，每个金额格式如：[100.00][99.01]
	 */
	@Column(name = "amounts", length=200)
	private String amounts;
	/**
	 * 允许交易月份（s），多选
	 */
	@Column(name = "mons", precision = 8, scale = 0, columnDefinition = "int(8) not null default '4095'")
	private Integer mons;
	/**
	 * 每月允许交易日（s），多选
	 */
	@Column(name = "days", precision = 15, scale = 0, columnDefinition = "int(8) not null default '2147483647'")
	private Long days;
	/**
	 * 每周允许交易日（s），多选
	 */
	@Column(name = "week_days", precision = 8, scale = 0, columnDefinition = "int(8) not null default '127'")
	private Integer weekDays;
	/**
	 * 每日允许交易时间（s），多选
	 */
	@Column(name = "hours", precision = 8, scale = 0, columnDefinition = "int(8) not null default '16777215'")
	private Integer hours;
	/**
	 * 每笔交易时间间隔（毫秒）
	 */
	@Column(name = "period", precision = 8, scale = 0, columnDefinition = "int(8) not null default '0'")
	private Integer period;
	/**
	 * 上次交易时间（毫秒值）
	 */
	@Column(name = "use_time", nullable = false, columnDefinition="bigint not null default '0'")
	private Long useTime;
	/**
     * 当日收款金额
     */
    @Column(name = "amount_cur_day", precision = 10, scale = 2, columnDefinition="decimal(15,2) not null default '0'")
    private BigDecimal amountCurDay;
    /**
     * 当月收款金额
     */
    @Column(name = "amount_cur_mon", precision = 10, scale = 2, columnDefinition="decimal(15,2) not null default '0'")
    private BigDecimal amountCurMon;
    /**
     * 累计收款金额
     */
    @Column(name = "amount_tot", precision = 10, scale = 2, columnDefinition="decimal(20,2) not null default '0'")
    private BigDecimal amountTot;
	@PrePersist
	public void prePersist() {
		if (null == amountMin) {
			amountMin = new BigDecimal("0.01");
		}
		if (null == amountMax) {
			amountMax = new BigDecimal("99999.99");
		}
		if (null == amountDay) {
			amountDay = new BigDecimal("99999999.99");
		}
		if (null == amountMon) {
			amountMon = new BigDecimal("9999999999.99");
		}
		if (null == sumType) {
			sumType = ConfineSumType.ORDER;
		}
		if (null == mons) {
			mons = 4095;
		}
		if (null == days) {
			days = 2147483647L;
		}
		if (null == weekDays) {
			weekDays = 127;
		}
		if (null == hours) {
			hours = 16777215;
		}
		if (null == period) {
			period = 0;
		}
		if (null == useTime) {
			useTime = System.currentTimeMillis();
		}
		if (null == amountCurDay) {
			amountCurDay = BigDecimal.ZERO;
		}
		if (null == amountCurMon) {
			amountCurMon = BigDecimal.ZERO;
		}
		if (null == amountTot) {
			amountTot = BigDecimal.ZERO;
		}
	}
	public Long getConfineId() {
		return confineId;
	}
	public void setConfineId(Long confineId) {
		this.confineId = confineId;
	}
	public BigDecimal getAmountMin() {
		return amountMin;
	}
	public void setAmountMin(BigDecimal amountMin) {
		this.amountMin = amountMin;
	}
	public BigDecimal getAmountMax() {
		return amountMax;
	}
	public void setAmountMax(BigDecimal amountMax) {
		this.amountMax = amountMax;
	}
	public BigDecimal getAmountDay() {
		return amountDay;
	}
	public void setAmountDay(BigDecimal amountDay) {
		this.amountDay = amountDay;
	}
	public BigDecimal getAmountMon() {
		return amountMon;
	}
	public void setAmountMon(BigDecimal amountMon) {
		this.amountMon = amountMon;
	}
	public Integer getMons() {
		return mons;
	}
	public void setMons(Integer mons) {
		this.mons = mons;
	}
	public Long getDays() {
		return days;
	}
	public void setDays(Long days) {
		this.days = days;
	}
	public Integer getWeekDays() {
		return weekDays;
	}
	public void setWeekDays(Integer weekDays) {
		this.weekDays = weekDays;
	}
	public Integer getHours() {
		return hours;
	}
	public void setHours(Integer hours) {
		this.hours = hours;
	}
	public BigDecimal getAmountCurDay() {
		return amountCurDay;
	}
	public void setAmountCurDay(BigDecimal amountCurDay) {
		this.amountCurDay = amountCurDay;
	}
	public BigDecimal getAmountCurMon() {
		return amountCurMon;
	}
	public void setAmountCurMon(BigDecimal amountCurMon) {
		this.amountCurMon = amountCurMon;
	}
	public BigDecimal getAmountTot() {
		return amountTot;
	}
	public void setAmountTot(BigDecimal amountTot) {
		this.amountTot = amountTot;
	}
	public String getAmounts() {
		return amounts;
	}
	public void setAmounts(String amounts) {
		this.amounts = amounts;
	}
	public Integer getPeriod() {
		return period;
	}
	public void setPeriod(Integer period) {
		this.period = period;
	}
	public Long getUseTime() {
		return useTime;
	}
	public void setUseTime(Long useTime) {
		this.useTime = useTime;
	}
	public ConfineSumType getSumType() {
		return sumType;
	}
	public void setSumType(ConfineSumType sumType) {
		this.sumType = sumType;
	}
	
}
